//
//  RaiseMenu.h
//  RaiseMenu: Main class of the game
//
//  Created by Enric Vergara on 20.10.12. 
//  Copyright OWLAB 2010. All rights reserved.
// Import the interfaces

#import "RaiseMenu.h"
#import "SoundManager.h"

// CRaiseMenu implementation
@implementation CRaiseMenu



// on "init" you need to initialize your instance
-(id) init
{
	// always call "super" init
	// Apple recommends to re-assign "self" with the "super" return value
	if ((self = [super init]))
    {
        m_iRaise = 1;
        m_iMaximumRaise = 1;
        //CGSize screenSize = [[CCDirector sharedDirector] winSize];
        CGPoint center = CGPointMake(0,0);
        //Definim el tapete del joc
        m_Background = [CCSprite spriteWithFile:@"menuExit_background.JPG"]; 
        m_Background.position =center;
        [self addChild:m_Background];

       [CCMenuItemFont setFontName:@"Arial"];
        [CCMenuItemFont setFontSize:40];
        m_Button_More = [CCMenuItemFont itemFromString:@"(+)" target:self selector:@selector(menuMore:)];
		m_Button_More.position =  CGPointMake( 30, -20);
        
        m_Button_Less = [CCMenuItemFont itemFromString:@"(-)" target:self selector:@selector(menuLess:)];
        m_Button_Less.position =  CGPointMake(-30, -20);

        m_Button_Accept = [CCMenuItemFont itemFromString:NSLocalizedString(@"Accept", @"") target:self selector:@selector(menuAccept:)];
        m_Button_Accept.position =  CGPointMake(- 100, -70);

        m_Button_Cancel = [CCMenuItemFont itemFromString:NSLocalizedString(@"Cancel", @"") target:self selector:@selector(menuCancel:)];
        m_Button_Cancel.position =  CGPointMake( 100, -70);
        
        
        // create the menu using the items
        m_Menu = [CCMenu menuWithItems:m_Button_More, m_Button_Less, m_Button_Accept, m_Button_Cancel, nil];
        m_Menu.position = center;
        [self addChild:m_Menu];
        m_Menu.visible = true;

        //label indicant Current Raise: XX $ (al principi com ma mínim en tindra 1 de aposta mínima)
        m_sTitleLabel = [CCLabel labelWithString: [NSLocalizedString(@"CurrentRaise", @"") stringByAppendingString:[NSString stringWithFormat: @"%d$", 1]] fontName:@"Arial" fontSize:40];
        [m_sTitleLabel setColor:ccc3(0,0,0)];
        [m_sTitleLabel setPosition:CGPointMake(center.x,center.y + 50)];
        [self addChild: m_sTitleLabel];
        
        
		// must be enabled if you want to receive touch events!
		self.isTouchEnabled = YES;
	}
	return self;
}

-(void) setMaximumRaise: (int) mr
{
    m_iMaximumRaise = mr;
}

-(int)  getRaise
{
    return m_iRaise;
}

-(void) ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{

}

-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    
}

-(void) menuMore: (id) sender
{
    if (!self.visible) return;
        
    m_iRaise++;
    if (m_iRaise > m_iMaximumRaise)
    {
        m_iRaise = m_iMaximumRaise;
    }
    else
    {
        [[SoundManager sharedInstance] playEffect:SOUND_BUTTON_SHOW_CARDS];
    }
    
    [m_sTitleLabel setString:[NSString stringWithFormat:@"%@%d$",NSLocalizedString(@"CurrentRaise", @""),m_iRaise]];
}

-(void) menuLess: (id) sender
{
    if (!self.visible) return;
    
    m_iRaise--;
    if (m_iRaise < 1)
    {
        m_iRaise = 1;
    }
    else
    {
        [[SoundManager sharedInstance] playEffect:SOUND_BUTTON_SHOW_CARDS];
    }
    
    [m_sTitleLabel setString:[NSString stringWithFormat:@"%@%d$",NSLocalizedString(@"CurrentRaise", @""),m_iRaise]];
}

-(void) menuAccept: (id) sender
{
    if (!self.visible) return;
    
    self.visible = false;    
    //Notificacio del raise que es vol fer.
    [[NSNotificationCenter defaultCenter] postNotificationName:@"LocalPlayer_AcceptRaise" object:nil];
    
    [[SoundManager sharedInstance] playEffect:SOUND_BUTTON_NEXT];
}

-(void) menuCancel: (id) sender
{
    if (!self.visible) return;
    
    self.visible = false;    
    [[SoundManager sharedInstance] playEffect:SOUND_BUTTON_CANCEL];
}


// on "dealloc" you need to release all your retained objects
-(void) dealloc
{
	// don't forget to call "super dealloc"
	[super dealloc];
}

@end
